home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / util / libs / DigNet.lha / dignet / dignetterm / source / DignetTerm.asm < prev    next >
Encoding:
Assembly Source File  |  1997-03-29  |  9.7 KB  |  333 lines

  1. *>b:DignetTERM
  2.  
  3.     *«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*
  4.     *   Copyright © 1997 by Kenneth C. Nilsen.  E-Mail: kennecni@IDGonline.no              *
  5.     *   Source viewed in 800x600 with Thin711.font (11) in CED                      *
  6.     *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  7.     *
  8.     *   Name
  9.     *    DignetTERM 2.1
  10.     *
  11.     *   Synopsis
  12.     *       Demo program for dignet.library to show one of the capability it has.
  13.     *
  14.     *   Function
  15.     *    Simple communication with the modem or a console in the other end. Feel free
  16.     *    to modify this program for your own needs.
  17.     *
  18.     *    This source demostrates the capability of the dignet.library. It will let you
  19.     *    communicate with a device, for example the serial.device. You can use this little
  20.     *    program to enter a BBS or the internet for that matter.
  21.     *    It is slower than for example NComm and Term due to that each read/write is called
  22.     *    as a library function with stack store/restore, reading and init of net structure
  23.     *    and etcetera. To make it as fast as those regular terminal programs you would have
  24.     *    to read the DoIO/SendIO your self, but then the point with this library is gone.
  25.     *
  26.     *    You can use the new function GetNetport to use a own console window and IDCMP with
  27.     *    Wait() on the signal collection of the ports. This way you can write your own
  28.     *    complete terminal program, but we will not stand for the speed it will give.
  29.     *
  30.     *    You could easily make modem and/or nullmodem support for your programs. To make them
  31.     *    modem capable you just send ATDT<number>(13)(10) and handle OK/CONNECT/ERROR returns.
  32.     *    Exclude that part and you have a nullmodem capable program.
  33.     *
  34.     *    If anything is unclear e-mail us at: kenny@bgnett.no
  35.     *
  36.     *   Inputs
  37.     *    DignetTERM <device> [unit]   unit defaults to 0 if not provided
  38.     *
  39.     *   Notes
  40.     *
  41.     *   Bugs
  42.     *    
  43.     *   Created    : 09.03.97
  44.     *   Changes    : 09.03.97, 13.03.97, 14.03.97, 15.03.97, 17.03.97
  45.     *««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*
  46.  
  47.  
  48. ;StartSkip    =    0
  49.  
  50. ;DODUMP        SET    1
  51.  
  52. BufferSize    =    1024*2
  53.  
  54.  
  55.         Incdir    ""
  56.  
  57.         include    lvo:exec_lib.i
  58.         include    lvo:dos_lib.i
  59.         include    lvo:dignet_lib.i
  60.  
  61.         Incdir    inc:
  62.  
  63. ;these two files are included:
  64.  
  65.         include    dignet/dignet.i
  66.         include    digital.macs
  67.         include    startup.asm
  68.  
  69.         Incdir    ""
  70.  
  71.         dc.b    "$VER: DignetTERM 2.1 (17.3.97)",10
  72.         dc.b    "Copyright © 1997 Digital Surface. PUBLIC DOMAIN",0
  73.         even
  74. *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  75. Init        TaskName    "DignetTERM"
  76.         DefLib    dignet,3        ;version 3+ of dignet.library
  77.         DefLib    dos,37            ;version 37 of dos.library
  78.         DefEnd
  79.  
  80. Start    NextArg                ;any args for this program ?
  81.     beq    About            ;none, show About/usage
  82.     move.l    d0,a0
  83.     cmp.b    #'?',(a0)        ;info wanted ? show About/Usage
  84.     beq    About
  85.  
  86.     lea    DevN(pc),a1        ;we asume a device name
  87.  
  88. .copyDevice
  89.     move.b    (a0)+,(a1)+        ;copy name to our own buffer
  90.     bne.b    .copyDevice        ;you could easily default this to serial.device
  91.  
  92.     NextArg                ;unit provided ?
  93.     beq    .noUnit            ;if no unit provided, default to 0
  94.  
  95.     move.l    d0,a0            ;this is just a demo so we take a simple convert
  96.     move.b    (a0),d0
  97.     ext.w    d0
  98.     ext.l    d0
  99.     sub.w    #48,d0            ;simple convert (!)
  100.     move.l    d0,Unit
  101.  
  102. .noUnit    LibBase    dignet
  103.  
  104.     lea    DevN(pc),a0        ;device we want to use
  105.     move.l    Unit(pc),d0        ;unit
  106.     Call    AllocNet        ;alloc a net structure
  107.     move.l    d0,Net            ;ok, it's ready for use
  108.     beq    ErrorNet
  109.  
  110. ;    move.l    d0,a0            ;problems with connect ? use this one..
  111. ;    Call    SetDefault
  112.  
  113. ;prepare console for in/out.
  114.  
  115.     LibBase    dos
  116.  
  117.     Call    Input            ;get def. input handler (CON)
  118.     move.l    d0,In            ;store
  119.     beq    Errorin
  120.  
  121.     Call    Output            ;get def. output handler (CON)
  122.     move.l    d0,Out
  123.     beq    Close            ;if error quit (nowhere to print message)
  124.  
  125.     move.l    In(pc),d1
  126.     moveq.l    #1,d2
  127.     Call    SetMode            ;set RAW mode so we don't have to wait until
  128.                     ;a CR (return button) is pressed
  129. ;Print Welcome text:
  130.  
  131.     lea    Welcome(pc),a0
  132.     bsr    Print
  133.  
  134.     LibBase    dignet
  135.  
  136.     move.l    Net(pc),a0
  137.     Call    FlushNet
  138.  
  139.     moveq.l    #-1,d0
  140.  
  141.     move.l    Net(pc),a0
  142.     lea    InitCmd(pc),a1        ;our optional command
  143.     lea    Buffer(pc),a2        ;result buffer from modem (OK|ERROR)
  144.     Call    InitModem        ;our new function
  145.     tst.l    d0            ;ok ?
  146.     beq    Main            ;d0=0 then ok (!)
  147.     cmp.l    #DNETERROR_TIMEOUT,d0    ;timed out?
  148.     bne.b    .noTO            ;nope..
  149.  
  150.     lea    TimedOut(pc),a0
  151.     bsr    Print            ;print timeout message and...
  152.  
  153. .noTO    lea    NoModem(pc),a0
  154.     bsr    Print            ;no modem connected? text
  155.  
  156. ; MAIN LOOP: Here we read char and modem and print from modem to CON
  157.  
  158. Main    LibBase    exec
  159.  
  160. ;check for ctrl + c:
  161.  
  162.     moveq    #0,d0
  163.     moveq    #0,d1
  164.     bset    #12,d1
  165.     Call    SetSignal        ;check for ctrl + c
  166.     btst    #12,d0
  167.     bne    Exit            ;yes ? then quit
  168.  
  169.     LibBase    dos
  170.  
  171.     move.l    In(pc),d1
  172.     move.l    #12000,d2        ;wait a while (this can be done better with signal
  173.                     ;handling etcetera..
  174.     Call    WaitForChar        ;wait for keypress
  175.     tst.l    d0
  176.     beq    .noChar            ;no key ? then check net only
  177.  
  178.     move.l    In(pc),d1        ;read from def. Input handler
  179.     move.l    #Buffer,d2        ;to buffer
  180.     moveq.l    #1,d3            ;only one char at the time
  181.     Call    Read            ;read char
  182.  
  183. ;echo/half duplex:            ;uncomment these line below to have
  184. ;    move.l    Out(pc),d1        ;echoing of what you write when you're online.
  185. ;    move.l    #Buffer,d2
  186. ;    moveq.l    #1,d3
  187. ;    Call    Write
  188.  
  189.     LibBase    dignet
  190.     move.l    Net(pc),a0
  191.     lea    Buffer(pc),a1        ;write from buffer
  192.     moveq.l    #1,d0            ;one char
  193.     Call    WriteNet        ;write char to net (modem perhaps)
  194.  
  195. .noChar    LibBase    dignet
  196.  
  197.     move.l    Net(pc),a0
  198.     Call    QueryNet        ;how many chars are waiting ?
  199.     tst.l    d0            ;none, then loop back to Main
  200.     beq    Main
  201.  
  202. ;read all chars in buffer
  203.  
  204.     move.l    Net(pc),a0
  205.     lea    Buffer(pc),a1        ;read to buffer
  206.     cmp.l    #BufferSize,d0
  207.     ble.b    .sizeOk
  208.     move.l    #BufferSize,d0        ;max chars (can be increased/decreased)
  209. .sizeOk    move.l    d0,d3
  210.     Call    ReadNet            ;read chars from net
  211.  
  212. ;print char to screen
  213.  
  214.     LibBase    dos
  215.     move.l    Out(pc),d1        ;write to def. output handler
  216.     move.l    #Buffer,d2        ;from buffer
  217.     Call    Write            ;print that char to screen
  218.  
  219. ;by printing the char you typed in CON you can provide echoing as well.
  220.  
  221.     bra    .noChar
  222.  
  223. Exit    lea    QuitText(pc),a0
  224.     bsr    Print
  225.  
  226.     LibBase    dos
  227.     move.l    In(pc),d1        ;input handler
  228.     moveq.l    #0,d2            ;set CON mode
  229.     Call    Setmode            ;set back to CON mode !!
  230. *------------------------------------------------------------------------------------------------------------*
  231. Close    LibBase    dignet            ;cleanup
  232.     tst.l    Net
  233.     beq.b    .noNet
  234.     move.l    Net(pc),a0
  235.     Call    FreeNet            ;free out net structure
  236.     tst.l    d0
  237.     beq    .noNet
  238.  
  239.     LibBase    dos
  240.     Call    Output            ;print error message if wrong net structure
  241.     move.l    d0,d1            ;well.. to show the options
  242.     beq    .noNet
  243.     move.l    #FreeError,d2
  244.     move.l    #FreeErrorL,d3
  245.     Call    Write
  246.  
  247. .noNet    Return    0            ;quit program with 0 in return code
  248. *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  249. ErrorIn
  250.     lea    NoInTxt(pc),a0        ;if no input handler available
  251.     bsr    Print            ;print error message
  252.     bra    Close
  253.  
  254. ErrorNet
  255.     LibBase    exec            ;report error on device/unit
  256.     lea    NoNetTxt(pc),a0
  257.     lea    Table(pc),a1
  258.     move.l    #DevN,(a1)
  259.     move.l    Unit(pc),4(a1)
  260.     lea    Proc(pc),a2
  261.     lea    Buffer(pc),a3
  262.     Call    RawDoFmt
  263.  
  264.     lea    Buffer(pc),a0
  265.     bsr    Print
  266.     bra    Close
  267.  
  268. About    lea    AboutTxt(pc),a0        ;About/Usage message
  269.     bsr    Print
  270.     bra    Close
  271.  
  272. Print    movem.l    d0-a6,-(sp)        ;our sub routine that prints to def. out
  273.  
  274.     LibBase    dos
  275.     move.l    a0,d2            ;backup string ptr.
  276.     Call    Output            ;get def. outhandler
  277.     move.l    d0,d1
  278.     beq    .exit            ;null ? then exit
  279.  
  280.     move.l    d2,a0            ;start count of length of string
  281.     moveq.l    #0,d3            ;length
  282. .count    tst.b    (a0)+            ;a null termination ?
  283.     beq.b    .print            ;yep, print
  284.     addq.l    #1,d3            ;no, add one more char
  285.     bra.b    .count            ;loop
  286. .print    Call    Write            ;write string to def Out which is our console
  287.  
  288. .exit    movem.l    (sp)+,d0-a6
  289.     rts
  290.  
  291. Proc    move.b    d0,(a3)+
  292.     rts
  293. *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  294. In        dc.l    0        ;input handler
  295. Out        dc.l    0        ;output handler
  296.  
  297. Net        dc.l    0        ;ptr. to net structure
  298. Table        dc.l    0,0        ;ptr. table for RawDoFmt()
  299.  
  300. Unit        dc.l    0        ;unit number
  301. DevN        dcb.b    80,0        ;device name, insert "serial.device" in beginning to def. to that
  302.  
  303. Buffer        dcb.b    BufferSize,0    ;buffer for chars and RawDoFmt()
  304. *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  305. Timedout    dc.b    "Timeout on line!",10,0
  306. NoModem        dc.b    "NO MODEM CONNECTED ?",10,10,0
  307.  
  308. Welcome        dc.b    12,"___________________________________________________________________________",10
  309.         dc.b    27,"[32m",27,"[1m",27,"[44m¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯",27,"[0m",10
  310.         dc.b    27,"[1m",27,"[44m          D I G N E T T E R M ",27,"[0m",27,"[44m 2.0 - 1997 by Kenny. Public Domain",27,"[1m          ",10
  311.         dc.b    27,"[44m___________________________________________________________________________",10
  312.         dc.b    27,"[32m",27,"[1m¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯",27,"[0m",10
  313.         dc.b    " This program demostrates some of the capabillities of the dignet.library.",10
  314.         dc.b    " Feel free to expande it for your own taste.    Note that the handler loop",10
  315.         dc.b    " isn't the most efficent way to handle in/out data.  You should convert it",10
  316.         dc.b    " a Wait() loop if you intend to release it in public.   The intention with",10
  317.         dc.b    " this program is demostration only.",10
  318.         dc.b    "___________________________________________________________________________",10
  319.         dc.b    27,"[32m",27,"[1m¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯",27,"[0m",10,0
  320.  
  321.  
  322. QuitText    dc.b    27,"[0m",12,"*** DignetTERM: CTRL+C BREAK",10,0
  323. NoNetTxt    dc.b    "Couldn't open %s unit %ld!",10,10,0
  324. NoInTxt        dc.b    "No input handler!",10,10,0
  325. AboutTxt    dc.b    "DignetTERM 1.2 demo program for dignet.library",10,10
  326.         dc.b    "USAGE: DignetTERM <device> [unit]",10,10
  327.         dc.b    "Press CTRL + C to quit",10,10,0
  328. FreeError    dc.b    "Error freeing net!",10
  329. FreeErrorL    =*-FreeError
  330.  
  331. InitCmd        dc.b    "ATZ\r",0
  332. *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  333.